using System.Runtime.Serialization;
using Trust.Casas.Model.Entities;
using Trust.Casas.Model.Exception;

namespace Trust.Casas.Model.Entities
{
    [DataContract]
    public class AppSettingInt : AppSetting
    {
        public override void SetValue(string value)
        {
            int setting;
            if (string.IsNullOrWhiteSpace(value))
                base.SetValue(value);
            else if (int.TryParse(value, out setting))
                base.SetValue(value);
            else
                throw new AppSettingValueInvalidFormatException();
        }

        public override object TypedValue
        {
            get
            {
                if (Value == null)
                    return default(int);
                return int.Parse(Value);
            }
        }
    }
}